package com.tchintech.pay.view.activity;

import android.os.Handler;
import android.os.Message;
import android.view.View;

import com.tchintech.pay.R;
import com.tchintech.pay.delegate.DealXxDelegate;
import com.tchintech.pay.frame.presenter.ActivityPresenter;
import com.tchintech.pay.model.entity.HttpCode;
import com.tchintech.pay.net.OkhttpClientTest;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/5 0005.
 * <p>
 * 交易记录详情
 */

public class DealXxActivity extends ActivityPresenter<DealXxDelegate> implements View.OnClickListener {
    private String ordernum;
    private Map<String, String> map;
    private Handler handler;
    private String deal_url = "Transaction.dealxx";

    @Override
    protected void initView() {
        super.initView();
        viewDelegate.setTv_title("交易详情");
        viewDelegate.setOnClickListener(this, R.id.iv_back);
        showMsg("商户订单号为" + ordernum);
        handler();
        query();
    }

    private void handler() {
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                hideProgressDialog();
                switch (msg.what) {
                    case HttpCode.networkabnormal:
                        showMsg("当前网络不可用");
                        break;
                    case HttpCode.http_failed:
                        showMsg("连接失败");
                        break;
                    case HttpCode.http_timeout:
                        showMsg("请求超时");
                        break;
                    case HttpCode.DELA_XX:
                        try {
                            JSONObject json = new JSONObject(msg.obj.toString());
                            if (json.getString("ret").equals("1")) {

                            } else {
                                showMsg(json.getString("msg"));
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        break;
                }
            }
        };
    }


    private void query() {
        map = new HashMap<String, String>();
        showProgressDialog("", "加载中，请稍后...");
        new OkhttpClientTest().path(this, handler, deal_url, map, HttpCode.DELA_XX);
    }

    @Override
    protected void initData() {
        super.initData();
        ordernum = getIntent().getStringExtra("ordernum");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }

    }

    @Override
    protected Class<DealXxDelegate> getDelegateClass() {
        return DealXxDelegate.class;
    }
}
